package com.atguigu.base64;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;

/**
 * 类说明：
 *
 * @author ChenCheng
 * @ClassName Base64Test
 * @create 2023-02-05 16:13
 * @Version 1.0
 */
public class Base64Test {
    public static void main(String[] args) throws Exception {
        String content = "这是需要Base64编码的内容";
        // 创建一个Base64编码器
        BASE64Encoder base64Encoder = new BASE64Encoder();
        // 执行Base64编码操作
        String encodedString = base64Encoder.encode(content.getBytes("UTF-8"));

        System.out.println(encodedString);

        // 创建Base64解码器
        BASE64Decoder base64Decoder = new BASE64Decoder();

        byte[] bytes = base64Decoder.decodeBuffer(encodedString);

        String str = new String(bytes, "UTF-8");

        System.out.println(str);

        String encode = new BASE64Encoder().encode("中国.jpg".getBytes("UTF-8"));
        System.out.println(encode);

    }
}
